package cardbs.servlets;
import static cardbs.dao.DAOFactory.*;
import static cardbs.dao.DepartmentDAO.*;
import static cardbs.domain.Department.*;
import static cardbs.servlets.CreatePartServlet.*;


import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cardbs.dao.DAOFactory;
import cardbs.dao.PartDAO;
import cardbs.domain.Deptype;
import cardbs.domain.Employee;
import cardbs.domain.Part;
import cardbs.domain.ServicePoint;


/** 
 * <!-- begin-UML-doc -->
 * <!-- end-UML-doc -->
 * @author marianna
 * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
 */
public class ShowPartsServlet extends HttpServlet{
	public ShowPartsServlet() {
		// TODO Auto-generated constructor stub
	}
	/** 
	 * <!-- begin-UML-doc -->
	 * <!-- end-UML-doc -->
	 * @param request
	 * @param response
	 * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) {
		// begin-user-code
		// TODO Auto-generated method stub
		String departmentCode;
		String page;
		HttpSession session = request.getSession(true);
		Employee administrator = (Employee)session.getAttribute("Administrator");
		departmentCode = request.getParameter("department");
		page = request.getParameter("page");
		Deptype depCode = Deptype.valueOf(Deptype.class, departmentCode);
		DAOFactory daoFactory = DAOFactory.getInstance();
		PartDAO partDAO = daoFactory.getPartDAO();
		Set<Part> part = partDAO.findAllPartsCode(depCode);
		HttpSession sess = request.getSession(true);
		sess.setAttribute("allParts", part);
		sess.setAttribute("employee", administrator);
		try {
			response.sendRedirect("/car-dbs-implementation/uipages/adminpages/"+page);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// end-user-code
	}
}